package org.mydba.report.gui;

import static org.mydba.report.gui.MyDBAReport.*;

import javax.swing.*;
import java.awt.*;

public class LegendPanel extends JPanel {
    private MyDBAReport report;
    private Font labelFont;
    private Font valueFont;

    LegendPanel(final MyDBAReport report) {
        this.report = report;
        setBackground(Color.WHITE);
        //setBorder(BorderFactory.createLineBorder(Color.black));
        labelFont = new Font("Verdana", Font.BOLD, 10);
        valueFont = new Font("Verdana", Font.PLAIN, 10);
    }

    public Dimension getPreferredSize() {
        return new Dimension(FRAME_WIDTH, 20);
    }

    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        final Graphics2D g2 = (Graphics2D) g;
        // Distinct sessions
        g2.setFont(labelFont);
        g2.drawString("Distinct sessions: ", 5, 15);
        g2.setFont(valueFont);
        g2.drawString(String.valueOf(report.getNumberOfDistinctSessions()), 115, 15);

        // Executing
        g2.setColor(Color.BLACK);
        g2.fillRect(FRAME_WIDTH - 280, 8, 14, 6);
        g2.setColor(EXECUTING_COLOR);
        g2.fillRect(FRAME_WIDTH - 280 + 1, 9, 13, 5);
        g2.setFont(labelFont);
        g2.setColor(Color.BLACK);
        g2.drawString("Executing", FRAME_WIDTH - 260, 15);

        // Updating
        g2.setColor(Color.BLACK);
        g2.fillRect(FRAME_WIDTH - 180, 8, 14, 6);
        g2.setColor(UPDATING_COLOR);
        g2.fillRect(FRAME_WIDTH - 180 + 1, 9, 13, 5);
        g2.setFont(labelFont);
        g2.setColor(Color.BLACK);
        g2.drawString("Updating", FRAME_WIDTH - 160, 15);

        // Fetching
        g2.setColor(Color.BLACK);
        g2.fillRect(FRAME_WIDTH - 80, 8, 14, 6);
        g2.setColor(FETCHING_COLOR);
        g2.fillRect(FRAME_WIDTH - 80 + 1, 9, 13, 5);
        g2.setFont(labelFont);
        g2.setColor(Color.BLACK);
        g2.drawString("Fetching", FRAME_WIDTH - 60, 15);
    }
}
